﻿package mortal.game.view.copy.groupCopy.view.vipCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class VipCopyRender extends GCellRenderer
    {
        private var _copyBitmap:GImageBitmap;
        private var _enterBtn:GLoadingButton;
        private var _vipLevel:BitmapNumberText;
        private var _limitNum:BitmapNumberText;
        private var _totalNum:BitmapNumberText;
        private var _tcopy:TCopy;
        private var _tvip:TVip;
        private var _itemList:Vector.<BaseItem>;

        public function VipCopyRender()
        {
            this._itemList = new Vector.<BaseItem>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._copyBitmap = UIFactory.gImageBitmap("", 0, 0, this);
            this._enterBtn = UIFactory.gLoadingButton(ResFileConst.EnterVipCopyBtn, 68, 480, 157, 37, this);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.enterCopy);
            this._vipLevel = UIFactory.bitmapNumberText(122, 31, "PetGrowYellowNum.png", 18, 21, -2, this, 9, BitmapNumberText.Mid);
            this._limitNum = UIFactory.bitmapNumberText(187, 418, "GroupCopyNum.png", 31, 35, -16, this, 13, BitmapNumberText.Mid);
            this._totalNum = UIFactory.bitmapNumberText(239, 418, "GroupCopyNum.png", 31, 35, -16, this, 13, BitmapNumberText.Mid);
            this._totalNum.text = "1";
            LoaderHelp.addResCallBack(ResFileConst.vipCopy, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._copyBitmap.dispose(param1);
            this._copyBitmap = null;
            this._limitNum.dispose(param1);
            this._limitNum = null;
            this._totalNum.dispose(param1);
            this._totalNum = null;
            this._vipLevel.dispose(param1);
            this._vipLevel = null;
            this._enterBtn.dispose(param1);
            this._enterBtn = null;
            this._tcopy = null;
            this._tvip = null;
            this._itemList.length = 0;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._tcopy = param1.tCopy;
            this._tvip = VipConfig.instance.getVipConfigByType(EVipRecordType._EVipRecordTypeVipCopy);
            this._copyBitmap.imgUrl = "vipCopyBg_" + (param1.index + 1) + ".jpg";
            this._totalNum.text = this._tcopy.dayNum.toString();
            this._limitNum.text = Cache.instance.copy.getTodayEnterTimes(this._tcopy.code).toString();
            this.updateBtnEnable();
            this.createItemList();
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.VipCopyNameBg, 33, 15, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.VipCopyNameBase, 80, 29, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_1, 15, 420, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_2, 200, 418, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_3, 255, 420, this));
            addChild(this._vipLevel);
            return;
        }// end function

        private function createItemList() : void
        {
            var _loc_2:BaseItem = null;
            var _loc_3:int = 0;
            if (this._itemList.length)
            {
                return;
            }
            var _loc_1:* = this._tcopy.rewardShow.split("#");
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(BaseItem);
                _loc_2.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBigBg, 4, 4);
                _loc_2.x = 10 + _loc_3 * 68;
                _loc_2.y = 80;
                _loc_2.isShowLock = true;
                var _loc_4:Boolean = false;
                _loc_2.isDropAble = false;
                _loc_2.isDragAble = _loc_4;
                addChild(_loc_2);
                _loc_2.itemData = new ItemData(int(_loc_1[_loc_3]));
                this._itemList.push(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                _loc_3++;
            }
            return;
        }// end function

        private function updateBtnEnable() : void
        {
            var _loc_1:* = Cache.instance.vip.level;
            var _loc_2:int = 1;
            while (_loc_2 <= 10)
            {
                
                if (this._tvip["vip" + _loc_2] == this._tcopy.code.toString())
                {
                    this._enterBtn.enabled = _loc_1 >= _loc_2;
                    this._enterBtn.drawNow();
                    this._vipLevel.text = _loc_2.toString();
                    break;
                }
                _loc_2++;
            }
            return;
        }// end function

        private function enterCopy(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupEnterCopyReq, this._tcopy));
            return;
        }// end function

    }
}
